<?php

declare(strict_types=1);

namespace App\Http\Admin\Controller\Ai;


use App\Http\Admin\Middleware\AuthMiddleware;
use App\Http\Common\Controller\AbstractController;
use App\Http\Common\Result;
use App\Request\ai\AppModelRequest;
use App\Request\ai\ChatModelRequest;
use App\Request\auth\Service\Ai\AppModelService;
use App\Request\auth\Service\Ai\ChatModelService;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\DeleteMapping;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Annotation\PutMapping;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\Validation\Annotation\Scene;

/**
 * 应用模型
 */
#[Middlewares([
    AuthMiddleware::class
])]
#[Controller(prefix: '/adminapi/ai/model/app')]
class AppModelController extends AbstractController
{

    public function __construct(
        protected readonly AppModelService $service
    )
    {
    }

    /**
     * 应用模型 列表
     * @param RequestInterface $request
     * @return Result
     */
    #[GetMapping('lists')]
    public function lists(RequestInterface $request): Result
    {
        $page = $this->service->getList($request->all());
        return $this->success($page);
    }

    /**
     * 应用模型 详情
     * @param int $id
     * @return Result
     */
    #[GetMapping('detail/{id}')]
    public function detail(int $id): Result
    {
        return $this->success($this->service->findById($id));
    }

    /**
     * 应用模型 创建
     * @param AppModelRequest $request
     * @return Result
     */
    #[Scene(scene: 'create', argument: 'request')]
    #[PostMapping('create')]
    public function create(AppModelRequest $request): Result
    {
        $this->service->create($request->all());
        return $this->success();
    }

    /**
     * 应用模型 更新
     * @param AppModelRequest $request
     * @return Result
     */
    #[Scene(scene: 'update', argument: 'request')]
    #[PutMapping('update')]
    public function update(AppModelRequest $request): Result
    {
        $this->service->updateById($request->input('id'), $request->all());
        return $this->success();
    }

    /**
     * 应用模型 更新状态
     * @param AppModelRequest $request
     * @return Result
     */
    #[Scene(scene: 'updateStatus', argument: 'request')]
    #[PutMapping('updateStatus')]
    public function updateStatus(AppModelRequest $request): Result
    {
        $this->service->updateById($request->input('id'), ['status' => $request->input('status')]);
        return $this->success();
    }

    /**
     * 应用模型 删除
     * @param int $id
     * @return Result
     */
    #[Scene(scene: 'delete')]
    #[DeleteMapping('delete/{id}')]
    public function delete(int $id): Result
    {
        $this->service->deleteById($id);
        return $this->success();
    }
}
